﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Upreader.Engine
{
    public class DownloadEngineConfiguration
    {
        #region Defaults

        public const int DefaultSegmentProcessorCollectionBufferSize = 128;
        public const int DefaultDownloadedSegmentProcessorCollectionBufferSize = 8;
        public const int DefaultCachedSegmentProcessorCollectionBufferSize = 2048;
        public const int DefaultSegmentsInMemoryCache = 8;
        public const int DefaultMaxObjectsToPersistBufferSize = 8;
        public const int DefaultFileAssembleCollectionBufferSize = 16;

        public const string DefaultDownloadStorageFolder = "Downloads";

        #endregion // Defaults

        #region Fields

        private int _segmentProcessorCollectionBufferSize = DefaultSegmentProcessorCollectionBufferSize;
        private int _downloadedSegmentProcessorCollectionBufferSize = DefaultDownloadedSegmentProcessorCollectionBufferSize;
        private int _cachedSegmentProcessorCollectionBufferSize = DefaultCachedSegmentProcessorCollectionBufferSize;
        private int _segmentsInMemoryCache = DefaultSegmentsInMemoryCache;
        private int _fileAssembleCollectionBufferSize = DefaultFileAssembleCollectionBufferSize;
        private string _downloadStorageFolder = DefaultDownloadStorageFolder;

        #endregion // Fields

        #region Properties

        /// <summary>
        /// Get or set the amount of segments that should be cached before waiting to load ore
        /// </summary>
        public int SegmentProcessorCollectionBufferSize
        {
            get { return _segmentProcessorCollectionBufferSize; }
            set { _segmentProcessorCollectionBufferSize = value; }
        }

        /// <summary>
        /// Get or set the amount of segments that can be queued for processing after download
        /// </summary>
        public int DownloadedSegmentProcessorCollectionBufferSize
        {
            get { return _downloadedSegmentProcessorCollectionBufferSize; }
            set { _downloadedSegmentProcessorCollectionBufferSize = value; }
        }

        /// <summary>
        /// Get or set the amount of segments that can be queued for processing after cached
        /// </summary>
        public int CachedSegmentProcessorCollectionBufferSize
        {
            get { return _cachedSegmentProcessorCollectionBufferSize; }
            set { _cachedSegmentProcessorCollectionBufferSize = value; }
        }

        /// <summary>
        /// Get or set the folder in which to store downloads and related files 
        /// </summary>
        public string DownloadStorageFolder
        {
            get { return _downloadStorageFolder; }
            set { _downloadStorageFolder = value; }
        }

        /// <summary>
        /// Get or set the amount of segments to cache in memory prior to writing it back to the disk. 
        /// When 0, no memory cache is used
        /// </summary>
        /// <remarks>
        /// This functionality can greatly affect disk IO since storing temporary segments will be out of the picture
        /// Consequently, setting this to a high number will affect memory consumption and shutdown time
        /// </remarks>
        public int SegmentsInMemoryCache
        {
            get { return _segmentsInMemoryCache; }
            set { _segmentsInMemoryCache = value; }
        }

        /// <summary>
        /// Get or set to amount of files that can be queued to be assembled simultaniously.
        /// </summary>
        public int FileAssembleCollectionBufferSize 
        {
            get { return _fileAssembleCollectionBufferSize; }
            set { _fileAssembleCollectionBufferSize = value; }
        }
        #endregion // Properties
    }
}
